package com.tran.app.viewmodel

import android.text.TextUtils
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavController
import com.orhanobut.logger.Logger
import com.tran.app.MyApp
import com.tran.app.dao.AppDatabase
import com.tran.app.data.Course
import com.tran.app.data.CourseSelection
import com.tran.app.data.LoginUi
import com.tran.app.data.RegisterUi
import com.tran.app.data.Teacher
import com.tran.app.data.UserInfo
import com.tran.app.utils.show
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

//选课老师
class SCViewModel : ViewModel() {





    val _uidata = MutableStateFlow(mutableListOf<Course>())
    val uidata: StateFlow<List<Course>> = _uidata.asStateFlow()

    init {
        viewModelScope.launch{
            withContext(Dispatchers.IO){
                _uidata.update {
                  val course = AppDatabase.getInstance(MyApp.instance).courseDao().getCoursesByTechName(MyApp.user)
                    course.toMutableList()
                }
            }
        }
    }
}